import request from '@/utils/request'

// 查询Archives列表
export function listArchives(query) {
    return request({
        url: '/api/v1/cms/archivesList',
        method: 'get',
        params: query
    })
}

// 查询Archives详细
export function getArchives(id) {
    return request({
        url: '/api/v1/cms/archives/' + id,
        method: 'get'
    }).then(function (res) {
        if (res.data.categoryIds != '') {
            res.data.categoryIdList = [];
            res.data.categoryIdList = res.data.categoryIds.split(',').map(item => {
                return +item;
            });
        }
        console.log(res);
        return res;
    })

}


// 新增Archives
export function addArchives(data) {
    //数据转换
    if (data.categoryIdList) {
        data.categoryIds = (data.categoryIdList).join(',');
    }

    return request({
        url: '/api/v1/cms/archives',
        method: 'post',
        data: data
    })
}

// 修改Archives
export function updateArchives(data) {
    //数据转换
    if (data.categoryIdList) {
        data.categoryIds = (data.categoryIdList).join(',');
    }
    return request({
        url: '/api/v1/cms/archives',
        method: 'put',
        data: data
    })
}

// 删除Archives
export function delArchives(id) {
    return request({
        url: '/api/v1/cms/archives/' + id,
        method: 'delete'
    })
}